package com.youku.plugins.commonui.view
{
   import flash.display.Sprite;
   import flash.display.DisplayObject;
   import flash.display.MovieClip;
   import com.youku.utils.DrawUtil;
   import com.youku.utils.AssetUtil;
   
   public class LoadingScreen extends Sprite
   {
      
      public function LoadingScreen(param1:DisplayObject = null) {
         super();
         this._whiteBG = DrawUtil.RectangleSprite(0,0,100,100,0,1,null,0);
         this._otherLoading = param1;
         this._background = new Sprite();
         this._background.graphics.beginFill(15595516);
         this._background.graphics.drawRect(0,0,610,498);
         this._background.graphics.endFill();
         this._loading = new Sprite();
         this._pic = AssetUtil.getAsset("Loading_pic") as MovieClip;
         this._pic.width = 158;
         this._pic.height = 46;
         this._action = AssetUtil.getAsset("Loading_Ring") as MovieClip;
         this._action.width = 36;
         this._action.height = 36;
         this._loading.addChild(this._pic);
         this._loading.addChild(this._action);
         this._pic.x = 0;
         this._pic.y = 54;
         this._action.x = 61;
         this._action.y = 0;
         this._loadingWidth = this._loading.width;
         this._loadingHeight = this._loading.height;
         if(this._otherLoading != null)
         {
            addChild(this._whiteBG);
            addChild(this._otherLoading);
         }
         else
         {
            addChild(this._whiteBG);
            addChild(this._background);
            addChild(this._loading);
         }
      }
      
      private var _whiteBG:Sprite;
      
      private var _background:Sprite;
      
      private var _otherLoading:DisplayObject;
      
      private var _loading:Sprite;
      
      private var _pic:MovieClip;
      
      private var _action:MovieClip;
      
      private var _width:Number;
      
      private var _height:Number;
      
      protected var _ratio:Number;
      
      protected var MINI_WIDTH:Number = 440;
      
      protected var MINI_HEIGHT:Number = 358;
      
      protected var MAX_WIDTH:Number = 900;
      
      protected var MAX_HEIGHT:Number = 500;
      
      protected var _loadingWidth:Number = 0;
      
      protected var _loadingHeight:Number = 0;
      
      public function setSize(param1:Number, param2:Number) : void {
         this._width = param1;
         this._height = param2;
         this._whiteBG.width = this._width;
         this._whiteBG.height = this._height;
         this._background.width = this._width;
         this._background.height = this._height;
         this._ratio = 1;
         if(param1 < this.MINI_WIDTH || param2 < this.MINI_HEIGHT)
         {
            if(param1 / this.MINI_WIDTH > param2 / this.MINI_HEIGHT)
            {
               this._ratio = param2 / this.MINI_HEIGHT;
            }
            else
            {
               this._ratio = param1 / this.MINI_WIDTH;
            }
         }
         if(param1 > this.MAX_WIDTH || param2 > this.MAX_HEIGHT)
         {
            if(param1 / this.MAX_WIDTH > param2 / this.MAX_HEIGHT)
            {
               this._ratio = param2 / this.MAX_HEIGHT;
            }
            else
            {
               this._ratio = param1 / this.MAX_WIDTH;
            }
         }
         this._loading.scaleX = this._ratio;
         this._loading.scaleY = this._ratio;
         this.updateLayout();
      }
      
      private function updateLayout() : void {
         this._whiteBG.x = 0;
         this._whiteBG.y = 0;
         this._background.x = 0;
         this._background.y = 0;
         this._loading.x = (this._width - this._loadingWidth * this._loading.scaleX) / 2;
         this._loading.y = (this._height - this._loadingHeight * this._loading.scaleY) / 2;
         if(this._otherLoading)
         {
            this._otherLoading.x = (this._width - this._otherLoading.width) / 2;
            this._otherLoading.y = (this._height - this._otherLoading.height) / 2;
         }
      }
   }
}
